package org.come.Frame;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.util.Map;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import org.come.until.FormsManagement;
import org.come.until.MessagrFlagUntil;
import org.come.until.Music;
import org.come.Jpanel.EventCalendarJpanel;

import com.tool.tcpimg.UIUtils;

public class EventCalendarJframe extends JInternalFrame implements MouseListener{

	private static EventCalendarJpanel eventCalendarJpanel;
	private int first_x,first_y;//x、y坐标

	public static EventCalendarJframe getEventCalendarJframe() {
		return (EventCalendarJframe) FormsManagement.getInternalForm(1104).getFrame();
	}

	public EventCalendarJframe() {
		super();
		eventCalendarJpanel=new EventCalendarJpanel();
		this.getContentPane().add(eventCalendarJpanel);

		this.setBorder(BorderFactory.createEmptyBorder());//去除内部窗体的边框
		((BasicInternalFrameUI)this.getUI()).setNorthPane(null);//去除顶部的边框

		this.setBounds(0, 0, 569, 501);//设置窗口出现的位置
		this.setBackground(UIUtils.Color_BACK);
		this.pack();
		this.setVisible(false);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		this.addMouseListener(this);
		this.addMouseMotionListener(new MouseMotionListener() {//判断窗口移动的位置
		
		@Override
		public void mouseMoved(MouseEvent e) {
		}
		
		@Override
		public void mouseDragged(MouseEvent e) {
			if (isVisible()) {
				int x = e.getX() - first_x;
				int y = e.getY() - first_y;
				setBounds(x + getX(), y + getY(),getWidth(),getHeight());
			}
		}
	});
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		//关闭按钮
		//开启窗口音效
		 Music.addyinxiao("关闭窗口.mp3");
		//打开了窗体
		if(e.isMetaDown()){//检测鼠标右键单击
			FormsManagement.HideForm(1104);
		}else {
			FormsManagement.Switchinglevel(1104);
			String text1 = "";
			String text2 = "";
			String text3 = "";
//			//system.out.println(this.first_x+","+this.first_y);
			Map<String, String> maps = eventCalendarJpanel.getMap();
			for(int i=1;i<=30;i++) {
				String[] xy = maps.get(i+"").toString().split(",");
				int x = Integer.parseInt(xy[0]);
				int y = Integer.parseInt(xy[1]);
				int xx = Integer.parseInt(xy[0])+ Integer.parseInt(xy[2]);
				int yy = Integer.parseInt(xy[1])+ Integer.parseInt(xy[3]);
				if(e.getX()>=x && e.getX()<=xx && e.getY()>=y && e.getY()<=yy) {
					
					if(maps.get(i+"一").toString()!="" && maps.get(i+"一").toString().length()>0) {
						text1=maps.get(i+"一");
					}
					if(maps.get(i+"二").toString()!="" && maps.get(i+"二").toString().length()>0) {
						text2=maps.get(i+"二");
					}
					if(maps.get(i+"三")!=null) {
						text3=maps.get(i+"三");
					}
					break;
				}
			}
			if(text1!="") {
				eventCalendarJpanel.labtext7.setText(text1);
			}else {
				eventCalendarJpanel.labtext7.setText(text1);
			}
			if(text2!="") {
				eventCalendarJpanel.labtext8.setText(text2);
			}else {
				eventCalendarJpanel.labtext8.setText(text2);
			}
			if(text3!="") {
				eventCalendarJpanel.labtext9.setText(text3);
			}else {
				eventCalendarJpanel.labtext9.setText(text3);
			}
		}
		this.first_x = e.getX();
		this.first_y = e.getY();
		
	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	public static EventCalendarJpanel getEventCalendarJpanel() {
		return eventCalendarJpanel;
	}

	public void setEventCalendarJpanel(EventCalendarJpanel eventCalendarJpanel) {
		EventCalendarJframe.eventCalendarJpanel = eventCalendarJpanel;
	}

	public int getFirst_x() {
		return first_x;
	}

	public void setFirst_x(int first_x) {
		this.first_x = first_x;
	}

	public int getFirst_y() {
		return first_y;
	}

	public void setFirst_y(int first_y) {
		this.first_y = first_y;
	}
}
